package com.cooper.dao.favorite;


import java.util.List;

import com.cooper.pagination.PageInfo;
import com.cooper.vo.DesignerVo;
import com.cooper.vo.ItemInfoVo;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.Paged;
import net.paoding.rose.jade.annotation.SQL;

@DAO
public interface FavoriteDAO {

	
	
	@SQL("select count(*)"
			+ " from d_like_detail l join d_item_info t on(l.outer_id=t.id and t.deleted='n' and l.deleted='n' )"
			+ " where l.origin='ITEM_LIKE' and l.score='1'"
			+ " #if(null !=:1){ and l.user_id=:1 } "
	)
	int queryFavoriteItemInfoCount(Long userId) throws Exception;
	
	@Paged(paramIndex=1)
	@SQL("select t.id,t.seller_id,t.cid,t.title,t.cn_name,t.price,t.quantity stock,"
			+ "(select origin_url from d_item_image a where t.id=a.item_id and a.deleted='n' and a.sort_no=1) main_url "
			+ " from d_like_detail l join d_item_info t on(l.outer_id=t.id and t.deleted='n' and l.deleted='n' )"
			+ " where l.origin='ITEM_LIKE' and l.score='1'"
			+ " #if(null !=:1){ and l.user_id=:1 } "
			)
	List<ItemInfoVo> queryFavoriteItemInfoList(Long userId, PageInfo pageInfo);
	
	
	@SQL("select count(*) from d_like_detail l join d_designer a on(l.outer_id=a.user_id and a.deleted='n' and l.deleted='n' ) where  l.origin='SHOP_LIKE' and l.score='1'"
			+ " #if(null !=:1){ and l.user_id=:1}")
	int queryFavoriteDesignerCount(Long userId);
	
	@Paged(paramIndex=1)
	@SQL("select a.id,a.user_id,a.store_name,a.seller_name,a.seller_file_id,a.company_name,a.contactor,a.favorite,"
			+ "a.brand_certificate,a.business_licence,a.passport,a.legal_passport,a.comments,"
			+ " (select zh_cn from d_location b,d_address d where b.id=d.country_id and d.origin='seller_address' and d.outer_id=a.user_id and d.deleted='n') country_name,"
			+ "(select count(*) from d_item_info b where b.deleted='n' and a.user_id=b.seller_id) item_count "
			+ " from d_like_detail l join d_designer a on(l.outer_id=a.user_id and a.deleted='n' and l.deleted='n' ) where  l.origin='SHOP_LIKE' and l.score='1'"
			+ " #if(null !=:1){ and l.user_id=:1}")
	List<DesignerVo> queryFavoriteShopList(Long userId, PageInfo pageInfo);
	
}
